package gruppe7.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ServletController {

	private static ServletController instance = new ServletController();
	
	public static ServletController getInstance() {
		return instance;
	}
	
	private ServletController() {
		
	}
	
	public Session getSession(HttpServletRequest request, HttpServletResponse response) {
		return new Session(request, response);
	}
	
	public boolean isSessionCreated(HttpServletRequest request) {
		HttpSession httpSession = request.getSession(false);
		
		if (httpSession != null) {
			String key = Session.UserKey;
			return httpSession.getAttribute(key) != null;
		}
		
		else return false;
	}
	
	public void sendToErrorPage(HttpServletResponse response) {
		
		try {
			response.sendError(500);
		}
		
		catch (Exception e) {
			// hmm - hvad gør man så?
			System.err.println(e.getStackTrace());
		}	
	}
	
	
	
	
	
}
